package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CustomerTransfer;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ICustomerTransferService;
import cn.wolfcode.crm.service.IEmployeeService;
import cn.wolfcode.crm.service.ISystemdictionaryItemService;
import cn.wolfcode.crm.util.JsonResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/customerTransfer")
public class CustomerTransferController {

    @Autowired
    private ICustomerTransferService CustomerTransferService;
    @Autowired
    private ISystemdictionaryItemService itemService;
    @Autowired
    private IEmployeeService employeeService;


    @RequiresPermissions(value={"移交历史列表","customerTransfer:list"},logical = Logical.OR)
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model) {
        //qo.setStatus(CustomerTransfer.STATUS_POTENTIAL);
        model.addAttribute("pageInfo", CustomerTransferService.query(qo));
        //查找所有的移交历史工作
        model.addAttribute("jobs", itemService.listItemByDicSn("job"));
        model.addAttribute("sources", itemService.listItemByDicSn("source"));
        model.addAttribute("cmds", itemService.listItemByDicSn("communicationMethod"));
        model.addAttribute("sellers", employeeService.listSellersByRoleSns("Market_Manager","Market"));
        return "customerTransfer/list";
    }

    @RequiresPermissions(value={"移交历史保存或更新","customerTransfer:saveOrUpdate"},logical = Logical.OR)
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(CustomerTransfer entity) {

        JsonResult result = new JsonResult();
        try {
            //int a=1/0;
            CustomerTransferService.saveOrUpdate(entity);
        }catch (Exception e)
        {
           e.printStackTrace();
            result.mark("保存失败");
        }
        return result;
    }


}
